/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui.utilities;

import core.exceptions.DBAccessException;
import db.DBAccessEngine;
import gui.GUIUtils;

import java.awt.Component;
import javax.swing.JOptionPane;

/**
 *
 * @author abadi
 */
public class Verifiers {

    static public boolean verifyEmail(String mail, Component comp) {
        if (!mail.contains("@")) {
            JOptionPane.showMessageDialog(comp, "Please enter a valid email", "Error", JOptionPane.ERROR_MESSAGE);
            return false;
        }
        return true;
    }

    static public boolean verifyUserName(String username, Component comp) {
        if (username.length() < 6) {
            JOptionPane.showMessageDialog(comp, "Username must be at least 6 charecters", "Error", JOptionPane.ERROR_MESSAGE);
            return false;
        }

        try {
            if (DBAccessEngine.User().exists(username)) {
                JOptionPane.showMessageDialog(comp, "Username already exists!", "Error", JOptionPane.ERROR_MESSAGE);
                return false;
            }
        } catch (DBAccessException ex) {
            GUIUtils.showMessageError(ex, comp);
        }
        return true;
    }

   
}
